package com.gf.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 时间格式化工具类
 * 
 * @author admin
 * 
 */
public class DateFormater {
	private static final Log logger = LogFactory.getLog(DateFormater.class);

	/**
	 * 把String转化为Date
	 * 
	 * @param date
	 * @return
	 */
	public static Date changeToDate(String date,String format) {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
		Date result = null;
		if (date != null) {
			try {
				result = simpleDateFormat.parse(date);
			} catch (ParseException e) {
				logger.info("时间转化出错!");
			}
		}
		return result;
	}

	/**
	 * 把date转化为String
	 * 
	 * @param date
	 * @return
	 */
	public static String changeToString(Date date,String format) {
		String result = null;
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
		if (date != null) {
			result = simpleDateFormat.format(date);
		}
		return result;
	}
}
